// Score reading , writting and sorting

var a=0,b=0, file,maxarray=0,combine="";
global.topten = ds_list_create();

switch(global.opt)
{
case "read":
if(!file_exists(working_directory + global.hiscorefile))
{
    file = file_text_open_append(working_directory + global.hiscorefile);
    file_text_write_string(file,"");
} else {
    
    file = file_text_open_read(working_directory + global.hiscorefile);
    while(!file_text_eof(file))
    {
        global.scores[a,b] = file_text_read_real(file);
        file_text_readln(file);
        b++;
        global.scores[a,b] = file_text_read_string(file);
        combine = string(global.scores[a,b-1]) +" "+ string(global.scores[a,b]);
        ds_list_add(global.topten,combine);
        a++;
        b--;
    }
}
file_text_close(file);
ds_list_sort(global.topten,false);

maxarray = array_length_2d(global.scores,0);
for(var i = 0; i < array_height_2d(global.scores);i++)
{
    for(var j = 0; j < array_length_2d(global.scores,i);j++)
    {
       
    }
}

break;

case "write":
if(global.playername <> "" && score > 0)
{
file = file_text_open_append(working_directory + global.hiscorefile);
    file_text_writeln(file);
    file_text_write_real(file,score);
    file_text_writeln(file);
    file_text_write_string(file,global.playername);
    file_text_close(file);
} else {
    global.err_msg = "Player Name or Score is Empty!"
}
break;
}

